package com.gem.mapper;

import com.gem.entity.Student;
import org.apache.ibatis.annotations.*;
import org.mybatis.caches.ehcache.EhcacheCache;

import java.util.List;

/**
 * @author 刘聪
 * Created  on 2020/10/9
 */
@CacheNamespace(implementation = EhcacheCache.class)
public interface StudentMapper {

    /*登录*/
    @Select("select * from student where name=#{name} and password=#{password}")
    Student login(@Param("name") String name, @Param("password") String password);

    /*添加学生*/
    @Insert("insert into student(name,studentNumber,password,birthday,gender,polity,brief) " +
            "values(#{name},#{studentNumber},#{password},#{birthday},#{gender},#{polity},#{brief})")
    void addStudent(Student student);


    /*删除学生信息*/
    @Delete("delete from student where id = #{id}")
    void delete(@Param("id") Long id);

    /*修改学生信息*/
    @Update("update student set name=#{name},password=#{password},birthday=#{birthday},gender=#{gender},polity=#{polity},brief=#{brief}" +
            "where id=#{id}")
    void editStudent(Student student);

    /*查询所有*/
    @Select("select * from student order by studentNumber")
    List<Student> selectAllStudent();

    /*查询学号*/
    @Select("select * from student where studentNumber=#{studentNumber}")
    Student searchStudentByNumber(@Param("studentNumber") String studentNumber);

    /*查询ID*/
    @Select("select * from student where id=#{id}")
    Student searchStudentById(@Param("id") Long id);

    /*查询姓名*/
    @Select("select * from student where name like concat('%',#{name},'%')")
    List<Student> selectByName(String name);
}
